package com.pubinfo.passbook.api.controller.auth;

import com.pubinfo.passbook.common.service.request.financial.RequestFinancialServer;
import com.pubinfo.passbook.common.service.request.tax.RequestTaxServer;
import com.pubinfo.passbook.common.entity.TSubsidiaryPrivateKey;
import com.pubinfo.passbook.common.model.bo.SubsidiaryInfo;
import com.pubinfo.passbook.common.model.dto.system.SubsidiaryPrivateKey;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.service.master.TSubsidiaryPrivateKeyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "private-key")
@Api(tags = "公司私钥管理")
@Slf4j
public class SubsidiaryPrivateKeyController {
  @Autowired
  TSubsidiaryPrivateKeyService keyService;
  @Autowired
  RequestFinancialServer financialServer;
  @Autowired
  RequestTaxServer taxServer;
  
  @PostMapping("saveOrUpdate")
  @ApiOperation(value = "新增/修改私钥")
  public JsonResult<Boolean> save(@RequestBody TSubsidiaryPrivateKey privateKey) {
    
    return JsonResult.success(keyService.saveOrUpdate(privateKey));
  }
  
  @PostMapping("list")
  @ApiOperation(value = "查询列表")
  public JsonResult<MyPage<SubsidiaryInfo>> list(@RequestBody SubsidiaryPrivateKey privateKey) {
    return JsonResult.success(new MyPage(keyService.listPrivateKey(privateKey)));
  }
  
  @PostMapping("check")
  @ApiOperation(value = "检查税务密钥是否正常")
  public JsonResult<List<String>> check() {
    return JsonResult.success(taxServer.check(null));
  }
  
  @PostMapping("checkFinancial")
  @ApiOperation(value = "检查财政密钥是否正常")
  public JsonResult<List<String>> checkFinancial() {
    return JsonResult.success(financialServer.checkFinancial(null));
  }
  
  @PostMapping("check/{id}")
  @ApiOperation(value = "根据主体id检查密钥是否正常")
  public JsonResult<List<String>> checkById(@PathVariable("id") String id) {
    return JsonResult.success(taxServer.check(id));
  }
  
  @DeleteMapping("remove/{id}")
  @ApiOperation(value = "删除私钥")
  public JsonResult<Boolean> removeFile(@PathVariable("id") String id) {
    return JsonResult.success(keyService.removeById(id));
  }
}
